PROGRAM	OpenSessionTest;

USES	{$U Memtypes.p	} Memtypes,
	   	{$U	Quickdraw.p	} Quickdraw,
	 	{$U OSIntf.p	} OSIntf,
		{$U	ToolIntf.p	} ToolIntf,
		{$U PackIntf.p	} PackIntf,
		{$U AppleTalk.p	} AppleTalk,
		{$U	PasLibIntf.p} PasLibIntf,
		{$U	IntEnv.p	} IntEnv,
		{$U nAppleTalk.p} nAppleTalk;
TYPE
XPPParmBlkHdl = ^XPPParmBlkPtr;

VAR

XPPh:		XPPParmBlkHdl;
i:			INTEGER;
SCBh:		Handle;

li,
asyncf:		LONGINT;

PROCEDURE	doHelp;
BEGIN
	WRITELN;
	WRITELN('T_OpenSession ASPTimeOut ASPRetry Net Node Socket AsyncFlag');
	WRITELN('	Returns -	ioResult,');
	WRITELN('				Session Ref. #,');
	WRITELN('				Handle to SCB,');
	WRITELN('				Handle to IOPB');
	WRITELN('	SCB & IOPB memory handles are locked until CloseSession or AbortOS called.');
	IEExit(0);
END;

PROCEDURE	showrslts;
BEGIN
	IF XPPh <> nil THEN
		WITH XPPh^^ DO
		BEGIN
			WRITELN;
			WRITELN('ioResult       = ',ioResult);
			WRITELN('Session Ref.   = ',SessRefNum);
			WRITELN('SCB Handle     = ',LONGINT(SCBh));
			WRITELN('IOPB Handle    = ',LONGINT(XPPh));
		END;
END;

PROCEDURE	abort(str:STRING);
BEGIN
	showrslts;
	WRITELN;
	WRITE('### Error - ');
	WRITELN(str);
	IF XPPh <> nil THEN
	BEGIN
		li := ABS(XPPh^^.ioResult);
		DisposHandle(Handle(XPPh));
	END
	ELSE
		li := 0;
	IF SCBh <> nil THEN
		DisposHandle(SCBh);
	IF li <> 0 THEN
		IEExit(li)
	ELSE
		IEExit(255);
END;

BEGIN
	SCBh := nil;
	XPPh := nil;
		
	IF ArgC <= 1 THEN
		EXIT(PROGRAM);
	IF EqualString(ArgV^[1]^,'HELP',FALSE,FALSE) THEN
		doHelp;
	IF ArgC <> 7 THEN
		abort('Not Enough Parameters, try HELP.');
	
	IF MPPOpen <> 0 THEN
		abort('Cannot open .MPP driver.');

	SetZone(SystemZone);
	Handle(XPPh) := NewHandle(SIZEOF(XPPParamBlock));
	HLock(Handle(XPPh));
	
	SCBh := NewHandle(SCBMemSize);
	HLock(SCBh);
	SetZone(ApplicZone);
	
	WITH XPPh^^ DO
	BEGIN
		ioResult := OpenXPP(i);
		IF ioResult <> 0 THEN
			abort('Could not open XPP driver.');
		ioRefNum := i;
		ioCompletion := Ptr(0);
		StringToNum(ArgV^[1]^,li);
		ASPTimeOut := li;
		StringToNum(ArgV^[2]^,li);
		ASPRetry := li;
		StringToNum(ArgV^[3]^,li);
		ServerAddr.aNet := li;
		StringToNum(ArgV^[4]^,li);
		ServerAddr.aNode := li;
		StringToNum(ArgV^[5]^,li);
		ServerAddr.aSocket := li;
		StringToNum(ArgV^[6]^,asyncf);
		SCBPointer := SCBh^;
		AttnRoutine := nil;
	END;
	
	IF asyncf <> 0 THEN
		IF ASPOpenSession(XPPh^,TRUE) <> 0 THEN
		ELSE
	ELSE
		IF ASPOpenSession(XPPh^,FALSE) <> 0 THEN;
	showrslts;
	IEExit(XPPh^^.ioResult);
END.
